package com.climber.spb_rabbitmq.spb_lazy.config;

import org.springframework.amqp.core.*;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.HashMap;
import java.util.Map;

/**
 * @author frx
 * @version 1.0
 * @date 2022/7/25  22:31
 * desc:TTL队列 配置文件类代码
 */
@Configuration
public class RabbitMQConfig {

    public static final String X_EXCHANGE="X";
    public static final String ROUTING_KEY_L = "XL";
    public static final String QUEUE_L = "lazy";
    public static final String QUEUE_P = "QP";



    @Bean("xExchange")
    public DirectExchange xExchange(){
        return new DirectExchange(X_EXCHANGE,false,false);
    }


//     @Bean("queueL")
//    public Queue queueL(){
//        Map<String, Object> args = new HashMap<>();
//        // 设置队列最大优先级
//        args.put("x-queue-mode", "lazy");
//        return QueueBuilder.nonDurable(QUEUE_L).withArguments(args).build();
//    }

    @Bean("queueL")
    public Queue queueL(){
        return QueueBuilder.nonDurable(QUEUE_L).lazy().build();
    }


    @Bean
    public Binding queueDBindingL(@Qualifier("queueL") Queue queueL,
                                  @Qualifier("xExchange") DirectExchange xExchange){
        return BindingBuilder.bind(queueL).to(xExchange).with(ROUTING_KEY_L);
    }


    @Bean("queueP")
    public Queue queueD(){
        return QueueBuilder.nonDurable(QUEUE_P).build();
    }

    //声明队列 QD 绑定 Y 交换机
    @Bean
    public Binding queueDBindingY(@Qualifier("queueP") Queue queueP,
                                  @Qualifier("xExchange") DirectExchange xExchange){
        return BindingBuilder.bind(queueP).to(xExchange).with("SSS");
    }

}
